﻿var dialogReturn_key = "EITC_DialogKey"; //保存弹出窗口的返回值的cookie键值
var PageCookie_key = "CSJXW_PageCookieKey"; //保存公共浏览记录的cookie键值


function SetFrameScroll(IsScroll, defaultValue) {
    if (IsScroll) {
        if (window.name == "ECTSdialogFrame") {
            window.document.body.scroll = "no";
        }
        else {
            if (defaultValue == "" || typeof (defaultValue) == "undefined") {
                window.document.body.scroll = "";
            }
            else {
                window.document.body.scroll = defaultValue;
            }
        }
    }
    else {
        window.document.body.scroll = "no";
    }
}

function ShowErrorMsg(title, messageId) {
    var defaultValue = window.document.body.scroll;
    SetFrameScroll(false, defaultValue);
    var strTemp = $("#" + messageId).get(0);
    strTemp.style.display = "none";
    ShowTopAlertCallback2(title, strTemp.innerHTML, '');
    iframeAutoFit(); //解决内页滚动  
}

function ShowAlert(title, message) {
    ShowAlertCallback(title, message, '');
}

function ShowAlertCallback(title, message, callback) {
    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { eval(callback) }
    });
}


function ShowTopAlert(title, message) {
    ShowTopAlertCallback(title, message, '');
}



function ShowAlertAndGoToURL(title, message, url) {
    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { window.location.href = url; }
    });
}

function ShowTopAlertAndGoToURL(title, message, url) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { window.location.href = url; }
    });
    $ = jQuery.noConflict();
}

function ShowTopAlertAndGoToParentURL(title, message, url) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { window.parent.location.href = url; }
    });
    $ = jQuery.noConflict();
}


function ShowTopAlertCallback(title, message, callback) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL>\r\n<LI>" + message + "</LI></UL>";
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { eval(callback) }
    });

    var buttons = $jParent(Content).dialog("option", "buttons").css("ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all");
    $ = jQuery.noConflict();
}

function ShowTopAlertCallback2(title, message, callback) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += message;
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); }
    }
]
    }).dialog({
        close: function() { eval(callback) }
    });
    $ = jQuery.noConflict();
}


function ShowDialog(title, url, callback, width, height) {
    window.removeiframe();
    var horizontalPadding = 30;
    var verticalPadding = 30;
    $('<iframe id="externalSite" frameborder="0" scrolling="auto" src="' + url + '" />').dialog({
        title: title,
        autoOpen: true,
        width: width,
        height: height,
        modal: true,
//        show: 'slide',
//        hide: 'slide',
        bgiframe: true,
        resizable: false,
        autoResize: false,
        overlay: {
            opacity: 0.5,
            background: "black"
        }
    }).width(width - horizontalPadding).height(height - verticalPadding).dialog({
        close: function() { eval(callback) }
    }).dialog("moveToTop");
}

function CloseDialog() {
    if (window.parent != null)
        window.parent.CloseShowDialogFrame();
}

function CloseShowDialogFrame() {
    $("#externalSite").dialog('close');
}
function removeiframe() {
    $("#externalSite").remove(0, 1);
}


function AlertAndCloseDialog(title, message) {
    ShowTopAlertCallback(title, message, "CloseDialog();");
}

function ShowTopDialog(title, url, callback, width, height) {
    var win = window;
    var frm = "";
    while (win.parent != null && win.parent != win) {
        frm = win.frameElement.id + "." + frm;
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    $jParent("#externalSite").remove(0, 1);


    var horizontalPadding = 30;
    var verticalPadding = 30;
    $jParent('<iframe id="externalSite" frameborder="0" scrolling="auto" src="' + url + '" />').dialog({
        title: title,
        autoOpen: true,
        width: width,
        height: height,
        modal: true,
//        show: 'slide',
//        hide: 'slide',
        bgiframe: true,
        resizable: false,
        autoResize: false,
        overlay: {
            opacity: 0.5,
            background: "black"
        }
    }).width(width - horizontalPadding).height(height - verticalPadding).dialog({
        close: function() { eval(callback) }
    }).dialog("moveToTop");
    $ = jQuery.noConflict();
}
function CloseTopDialog() {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();
    $jParent("#externalSite").dialog('close');
    $ = jQuery.noConflict();
}


function AlertAndCloseTopDialog(title, message) {
    ShowTopAlertCallback(title, message, "CloseTopDialog();");
}


function setCookie(arg_CookieName, arg_CookieValue, arg_CookieExpireDays) {
    if (arg_CookieExpireDays != null) {
        var todayDate = new Date();
        todayDate.setDate(todayDate.getDate() + arg_CookieExpireDays);
        document.cookie = arg_CookieName + "=" + arg_CookieValue + ";path=/;expires=" + todayDate.toGMTString() + ";";
    }
    else {
        var todayDate = new Date();
        todayDate.setDate(todayDate.getDate() + 1);
        document.cookie = arg_CookieName + "=" + arg_CookieValue + ";path=/;expires=" + todayDate.toGMTString() + ";";
    }
}

function getCookie(arg_CookieName) {
    var Found = false;
    var start, end;
    var i = 0;
    var cookieName = arg_CookieName + "=";
    while (i <= document.cookie.length) {
        start = i; end = start + cookieName.length;
        if (document.cookie.substring(start, end) == cookieName) {
            Found = true; break;
        }
        i++;
    }

    if (Found == true) {
        start = end;
        end = document.cookie.indexOf(";", start);
        if (end < start) {
            end = document.cookie.length;
        }
        return document.cookie.substring(start, end);
    }
    return "";
}


function ShowTopConfirm(title, message, callback) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); eval(callback); }
    },
    {
        text: "取消",
        click: function() { $jParent(this).dialog("close"); }
    }
]
    });
    $ = jQuery.noConflict();
}



function ShowTopConfirmYesAndNo(title, message, callbackYes, callbackNo) {
    var win = window;
    while (win.parent != null && win.parent != win) {
        win = win.parent;
    }
    var $jParent = win.jQuery.noConflict();

    Content = "<div id='dialog-message' title='" + title + "'>";
    Content += "<UL><LI>" + message + "</LI></UL>";
    Content += "</div>";

    $jParent(Content).dialog({
        width: 400,
        height: 150,
        modal: true,
        resizable: false,
        autoResize: false,
        buttons: [
    {
        text: "确定",
        click: function() { $jParent(this).dialog("close"); eval(callbackYes); }
    },
    {
        text: "取消",
        click: function() { $jParent(this).dialog("close"); eval(callbackNo); }
    }
]
    });
    $ = jQuery.noConflict();
}


function TransferLogin(url) {
    if (window.parent != null) {
        window.parent.location.href = url;
    }
    else {
        window.location.href = url;
    }
}

function OpenWin(src, width, height, left, top) {
    var fecture = "height=" + height + ", width=" + width + ", toolbar= no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no,"
    if (top != null) {
        fecture += "top=" + top;
    }
    else {
        fecture += "top=50";
    }
    if (left != null) {
        fecture += ",left=" + left;
    }
    else {
        fecture += ",left=100";
    }
    window.open(src, "",
                 fecture);
}